package com.suisung.shopsuite.agent.componet.anwser;

import com.suisung.shopsuite.agent.componet.anwser.base.AiResponseHandler;
import com.suisung.shopsuite.agent.componet.anwser.base.AiResponseHandlerChain;
import com.suisung.shopsuite.agent.componet.anwser.base.ResponseContext;

import java.util.LinkedList;
import java.util.List;

// 责任链实现
public class DefaultAiResponseHandlerChain implements AiResponseHandlerChain {
    private final List<AiResponseHandler> handlers;
    private int index = 0;

    public DefaultAiResponseHandlerChain(List<AiResponseHandler> handlers) {
        this.handlers = new LinkedList<>(handlers);
    }

    @Override
    public void proceed(ResponseContext context) {
        if (index < handlers.size()) {
            AiResponseHandler handler = handlers.get(index++);
            if (!handler.handle(context, this)) {
                // 处理器返回false，终止链式调用
            }
        }
    }
}
